/*
 * jQuery set form from object
 * no examples or documentation - just $('#form_id' ).setFromObj( obj );
 * Copyright 2011 TMLA INC
 * Written by Tim Gallagher
 * Version: 0.2 2011-11-24
	This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>
 */
;(function($)
{
	$.fn.
	setFromObj = function( obj )
	{
		$(this).find( ':input' ).map(
		function( index, elm)
		{
			if ( elm.name == '' )
			{
				return;
			}

			if ( elm.type == 'checkbox' )
			{
				if ( obj[elm.name] )
				{
					$(elm).attr( 'checked', 'checked' )
				}
				else
				{
					$(elm).removeAttr( 'checked' );
				}
			}
			else if ( elm.type != 'submit' )
			{
				$(elm).val( obj[elm.name] );
			}
		});
	};
	
})( jQuery );
